<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="com.sims.user.UserDAO"%>
<%@ page import="com.sims.vo.UserType"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="com.sims.util.DataTypeChange"%>
<%@ page import="com.sims.util.PrintUserPrivilege"%>

<html>
<head>
	<title>学生信息管理系统</title>
	
	<link rel="stylesheet" href="/sims/css/sims_main.css" type="text/css" />
	<link rel="stylesheet" href="/sims/css/sims_tab.css" type="text/css" />
	<link rel="stylesheet" href="/sims/css/sims_table.css" type="text/css" />

	<script type="text/javascript" src="/sims/js/sims.js" charset="GBK"></script>
	
</script>
	
</head>

<body>
		<% 
		    String userName=(String)session.getAttribute("username");
			int[] userrights = (int[])session.getAttribute("userrights");
			UserDAO ud = new UserDAO();
		    if (userName != null && ud.checkUserInfo(userName))
		    {
		%>
		    	<div id="header">
				<span id="logoTxt" class="logo">&nbsp;学生信息管理系统</span>
				<span id="loginname" class="username">当前用户：
				<%
					out.println(userName);
				%>
				&nbsp;&nbsp;</span>
				<a class="logout" href="/sims/pages/logout.jsp">注销</a>
				</div>

				<div id="menu">
				<ul id="tab">
					<% 
						if (userrights[0]==1)
						{
					%>
					<li><a href="/sims/pages/default.jsp">信息管理</a></li>
					<% 
						}
						if (userrights[1]==1)
						{
					%>
					<li><a href="/sims/pages/changepwd.jsp">密码管理</a></li>
					<% 
						}
						if (userrights[2]==1)
						{
					%>
					<li><a href="/sims/pages/right.jsp">权限管理</a></li>
					<% 
						}
					%>
				</ul>
				</div>

				<div id="content">
				
				<form name="queryrights" method="POST">
				
				<table align = "left" > 
          		<tr>
         			<td><input type ="button" value ="新增角色"  onClick="location.href='creatrole.jsp'" style="margin-left: 10px;"/></td>
         			<td><input type ="button" name="batchdelete" value ="批量删除"  onClick="batchDelete('c')"/></td>
         		</tr>
     			</table>
				
         		<table class="dataintable">
             	<tr align="center">
                 	<th><input type="checkbox" name="deletenum" onclick="check_all(this,'c')"/>全选</th>
                 	<th>角色编号</th>
                 	<th>角色名称</th>
                 	<th>角色权限</th>
                 	<th>角色描述</th>
                	<th colspan="2">操作</th>
            	</tr>
           
            	<%
            	ArrayList<UserType> rights = ud.queryRights();
            	for(int i = 0 ; i<rights.size();i++) 
            	{
            		UserType right = rights.get(i);
               	%>
                <tr align="center" >
                	<td><input type="checkbox" value='<%=right.getUserTypeId()%>' name="c"/></td>
                	<td><%=right.getUserTypeId()%></td>
                	<td><%=right.getUserTypeName()%></td>
                	<td><%
                	
                	String userrightsbak = right.getUserRight();
                	DataTypeChange dtc = new DataTypeChange();
                	int[] rightsint = dtc.stringToIntArray(userrightsbak);
                	PrintUserPrivilege pup = new PrintUserPrivilege();
                	out.print(pup.printUserPrivilege(rightsint));
                	%></td>
                	<td><%=right.getUserDescription()%></td>
                	<td><a href='javascript:deleteUserType("<%=right.getUserTypeId()%>")' style="text-decoration: none;">删除</a></td>
                	<td><a href="updaterole.do?userTypeId=<%=right.getUserTypeId()%>" style="text-decoration: none;">修改</a></td>
            	</tr>
             	<% 
             	}
             	%>
         		</table>
     			
     			</form>
				
				</div>

				<div id="footer">Copyright no right</div>
				<% 
						String errMsg = (String)request.getSession().getAttribute("Message");
						if (errMsg != null)
						{
							out.println("<SCRIPT LANGUAGE='JavaScript'>");
							out.println("alert('"+errMsg+"')");
							out.println("</SCRIPT>");
							request.getSession().removeAttribute("Message");
						}
						else
						{
							out.println("");
						}
				%>
		<%
		    }
		    else
		    {
		    	response.sendRedirect("/sims/index.jsp");
		    }
		%>		
</body>
</html>